package com.sogoodsoft.dao.crm.report;

import java.util.List;

import org.hibernate.SQLQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.sogoodsoft.dao.common.CommonHibernateDao;

@Component
public class ReportDao extends CommonHibernateDao<Object, Long> {

	Logger logger = LoggerFactory.getLogger(getClass());
	@SuppressWarnings("unchecked")
	public List<Object> query(String sql,Object...obj){
		logger.debug("报表SQL查询："+sql);
		logger.debug("报表实际传递参数："+obj.length+"个");
		SQLQuery query = this.getSession().createSQLQuery(sql);
		for(int i=0;i<obj.length;i++){
			query.setParameter(i, obj[i]);
		}
		
		logger.debug("报表查询结果：");
		List<Object> list = query.list();
		for(Object o:list){
			Object[] os = (Object[])o;
			StringBuffer buffer = new StringBuffer();
			buffer.append("\t");
			for(Object t:os){
				buffer.append(String.valueOf(t));
				buffer.append("\t");				
			}
			logger.debug(buffer.toString());
		}
		return list;
	}
	

}
